package com.redhipps.hips.client.widget;

import java.util.List;

import com.google.gwt.user.client.ui.Hyperlink;
import com.redhipps.hips.client.command.CreateInstitutionCommand;
import com.redhipps.hips.client.controller.EditCallback;
import com.redhipps.hips.client.controller.ModelEditDelegate;
import com.redhipps.hips.client.model.Context;
import com.redhipps.hips.client.model.Institution;

public class InstitutionList extends ModelList<Institution> {

  private static String[] HEADERS = { "Name" };

  public InstitutionList(Context ctx, List<Institution> values) {
    super(ctx, values);
    setEditingDelegate(new InstitutionListEditDelegate());
    refresh();
  }

  @Override
  protected Object[] headers() {
    return HEADERS;
  }

  @Override
  protected Object[] writeModel(Institution model, int row) {
    Hyperlink hyperlink = new Hyperlink(model.getName(), "institutionList");
    hyperlink.addClickListener(createModelSelectionClickListener(model));
    return new Object[] { hyperlink };
  }

  private static class InstitutionListEditDelegate implements ModelEditDelegate<Institution> {

    public void createModel(Context context, EditCallback<Institution> callback) {
      invokeWithEditCallback(new CreateInstitutionCommand(), context, callback);
    }

    public void deleteModel(Context context, Institution model,
        EditCallback<Institution> callback) {
      // TODO Auto-generated method stub   
    }

    public void editModel(Context context, Institution model, EditCallback<Institution> callback) {
      // TODO Auto-generated method stub
    }
    
  }
}
